package com.yulp.springboot2task.test;


import com.yulp.springboot2task.service.TestJesQueImpl;
import com.yulp.springboot2task.utils.DateUtil;
import com.yulp.springboot2task.utils.SpringContext;

public class PaymentConsumerRetryHandler implements Runnable {

    /**
     * 如果有多个job，可以将这4个参数提出来，做成父类 RetryConsumer 继承；
     */
    private String topic;

    private String message;

    private Integer retries;

    private String nextRetryTime;

    public PaymentConsumerRetryHandler(String topic, String message, Integer retries, String nextRetryTime){
        this.topic = topic;
        this.message = message;
        this.retries = retries;
        this.nextRetryTime = nextRetryTime;
    }

    @Override
    public void run() {
        System.out.println(DateUtil.currentDateLong()+ "任务执行："+topic+"--"+message+"--"+retries);
        try {
        	// 业务判断(调用service接口)，如果失败继续执行
        	if (true) {
                TestJesQueImpl testJesQueImpl = SpringContext.getBeanByClass(TestJesQueImpl.class);
                testJesQueImpl.a1("topic2", message, retries);
        	}
        } catch (Exception e) {
            // 异常直接重试 testJesQueImpl.a1()
            e.printStackTrace();
        }
    }
}
